package com.cloudeasy.api.exception;

import com.cloudeasy.api.enums.ResultCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 全局异常
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class CloudEasyException extends RuntimeException {
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 根据结果状态码枚举构造
     *
     * @param resultCodeEnum {@link ResultCodeEnum}
     */
    public CloudEasyException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    /**
     * 自定义构造
     *
     * @param code    状态码
     * @param message 消息
     */
    public CloudEasyException(Integer code, String message) {
        super(message);
        this.code = code;
    }
}
